<template>
  <el-dialog v-model="dialogVisible" width="600" @closed="dialogClose">
    <div class="icon">
      <el-image :src="warningPng" mode="aspectFit" />
    </div>
    <div class="txt">{{ props.message }}</div>
    <div class="btn-group">
      <div class="wh-btn primary" @click="confirm">确定</div>
      <div class="wh-btn info" @click="cancel" v-if="props.showCancel">
        取消
      </div>
    </div>
  </el-dialog>
</template>
<script lang="ts" setup>
import { ref, render } from "vue";
import warningPng from "@/assets/img/warning.png";
const emit = defineEmits(["confirm", "cancel"]);
const props = defineProps({
  show: {
    type: Boolean,
    default: false
  },
  message: {
    type: String,
    default: ""
  },
  showCancel: {
    type: Boolean,
    default: false
  },
  confirmFn: {
    type: Function
  }
});

const dialogVisible = ref(props.show);

function dialogClose() {
  // render(null, document.body);
}
function showDialog() {
  dialogVisible.value = true;
}
function confirm() {
  dialogVisible.value = false;
  if (props.confirmFn) {
    props.confirmFn();
  }
  emit("confirm");
}
function cancel() {
  dialogVisible.value = false;
  emit("cancel");
}
defineExpose({
  confirm,
  cancel,
  showDialog
});
</script>
<style lang="scss" scoped>
.el-dialog {
  .icon {
    margin-top: 30px;
    display: flex;
    justify-content: center;
  }
  .txt {
    margin-top: 30px;
    font-size: 22px;
    font-weight: bold;
    text-align: center;
    letter-spacing: 0em;

    color: #3f4254;
  }
  .btn-group {
    margin-top: 60px;
    display: flex;
    align-items: center;
    justify-content: space-around;
    .wh-btn {
      width: 200px;
      height: 50px;
      border-style: solid;
    }
  }
}
</style>
